

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using JTC.MiniCommerce.Core;
using JTC.MiniCommerce.Localization;
using JTC.MiniCommerce.Store.Web.Controls;
using JTC.MiniCommerce.Store;

namespace JTC.MiniCommerce.Web.controls.navigation {
  public partial class favoriteproducts : SiteControl {

    #region Page Events

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        LoadFavoriteProducts();
      }
      catch (Exception ex) {
        Logger.Error(typeof(favoriteproducts).Name + "Page_Load", ex);
      }
    }

    #endregion

    #region Methods

    #region Protected

    /// <summary>
    /// Gets the product URL.
    /// </summary>
    /// <param name="productId">The product id.</param>
    /// <returns></returns>
    protected string GetProductUrl(string productId) {
      return string.Format("~/product.aspx?pid={0}", productId);
    }

    #endregion

    #region Private

    /// <summary>
    /// Loads the favorite products.
    /// </summary>
    private void LoadFavoriteProducts() {
      if (base.MasterPage.SiteSettings.CollectBrowsingProduct) {
        DataSet ds = new ProductController().FetchFavoriteProducts(WebUtility.GetUserName());
        if (ds.Tables[0].Rows.Count > 0) {
          LocalizationUtility.AddPanelText(pnlFavoriteProducts);
          rptrFavoriteProducts.DataSource = ds;
          rptrFavoriteProducts.DataBind();
        }
      }
    }

    #endregion

    #endregion

  }
}